//
//  HEHealthAlarmCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/31.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEHealthAlarmCell.h"

@interface HEHealthAlarmCell ()

@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *contentLb;
@property (nonatomic, strong) UILabel *descLb;
@property(nonatomic, strong) UISwitch *openBtn;

@end

@implementation HEHealthAlarmCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = KWhiteColor;
        
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _timeLb = [[UILabel alloc] init];
    _timeLb.font = DYBlodFont(18);
    _timeLb.text = @"2020-12-11 15:11";
    _timeLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_timeLb];
    
    _descLb = [[UILabel alloc] init];
    _descLb.font = DYFont(16);
    _descLb.text = @"张医生";
    _descLb.textColor = CNavBgColor;
    _descLb.numberOfLines = 0;
    [self.contentView addSubview:_descLb];
    
    _contentLb = [[UILabel alloc] init];
    _contentLb.font = DYFont(16);
    _contentLb.text = @"张医生";
    _contentLb.textColor = CNavLightBlackColor;
    _contentLb.numberOfLines = 0;
    [self.contentView addSubview:_contentLb];
    
    
    _openBtn = [UISwitch new];
    _openBtn.on = YES;
   [_openBtn addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];   // 开关事件切换通知
   [self.contentView addSubview:_openBtn];
    
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_timeLb.mas_bottom).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_openBtn.mas_left).mas_offset(-10);
    }];
    
    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_descLb.mas_bottom).mas_offset(5);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_openBtn.mas_left).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [_openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
}

- (void)setModel:(HEHealthAlarmModel *)model {
    _model = model;
    _timeLb.text = model.alarm_time;
    _descLb.text = model.alarm_title;
    _contentLb.text = model.KAllWeak;
    
    _openBtn.on = model.alarm_state == 0 ? YES:NO;
}

-(void)switchChange:(UISwitch *)sender{
    if ([_delegate respondsToSelector:@selector(cellOpenNotice:status:)]) {
        [_delegate cellOpenNotice:_model status: sender.on == YES ? 0 : 1];
    }
}

@end
